<?php

	function displayAffirmMessage($msg)
	{
		echo "<div class=\"blueborder\">
				<div class=\"messagebox\">
					<h3 class=\"confirmquestion\">".$msg."</h3>
				</div>
			</div>";
	}
	
	function displayErrorMessage($msg)
	{
		echo "<div class=\"redborder\">
				<div class=\"messagebox\">
					<h3 class=\"confirmquestion\">".$msg."</h3>
				</div>
			</div>";
	}

	function displayConfirmation()
	{
		$tmpstr = "<form action=\"".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."\" method=\"post\">";
		$tmpstr .= "<div class=\"blueborder\"><div class=\"messagebox\">";
		$tmpstr .= "<h3 class=\"confirmquestion\" style=\"padding-bottom: 3px; color: #0066ff;\">Are you sure you want to submit this entry?</h3>";
		foreach ($_POST as $key=>$value)
			$tmpstr .= "<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
		$tmpstr .= "<input type=\"submit\" name=\"submit\" value=\"Yes\" /><input type=\"submit\" name=\"submit\" value=\"No\" />";
		$tmpstr .= "</div></div></form>";
		return $tmpstr;
	}
	
	function displayErrors($arr)
	{
		$tmpstr = "<div class=\"redborder\"><div class=\"messagebox\">";
		$tmpstr .= "<h3 class=\"confirmquestion\" style=\"padding-bottom: 2px;\">An error has occured</h3><ul style=\"padding-left: 20px;\">";
		foreach ($arr as $key=>$value)
			$tmpstr .= "<li style=\"color: #555555;\">$value[1]</li>";
		$tmpstr .= "</ul></div></div>";
		return $tmpstr;
	}
	
	function displayNextPrev($pagenum,$last)
	{
		echo "<div style=\"float: right;\">";
		
		// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
		if ($pagenum != 1)
		{
			echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1".chopQueryString($_GET,array("pagenum"))."' title='First Page'> &laquo; First</a> ";
			$previous = $pagenum-1;
			echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous".chopQueryString($_GET,array("pagenum"))."' title='Previous Page'> &lsaquo; Prev</a> ";
		}

		//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
		if ($pagenum != $last)
		{
			$next = $pagenum+1;
			echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next".chopQueryString($_GET,array("pagenum"))."' title='Next Page'>Next &rsaquo;</a> ";
			echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last".chopQueryString($_GET,array("pagenum"))."' title='Last Page'>Last &raquo;</a> ";
		}

		echo "</div>";
	}
	
	function displayQCategories($qcategory)
	{
		echo "<table cellspacing=\"0\">";
		//This is where you display your query results
		while(!$qcategory->EOF)
		{
//			echo "<tr><td>".$qcategory->fields["name"]."</td></tr>";
			echo "<tr><td><a href='../qcategory/editqcategory.php?i=".$qcategory->fields["id"]."'>".$qcategory->fields["name"]."</a></td></tr>";
			$qcategory->MoveNext(); 
		}

		echo "</table>";							
	}
		
	function displayQuestions($question)
	{
		echo "<table cellspacing=\"0\">";
		//This is where you display your query results
	$qcategories = array();
		while(!$question->EOF)
		{
		$qcategoryid = $question->fields["qcategoryid"];
		$sqlQuery = "SELECT * FROM qcategory WHERE id = ".$qcategoryid;
		//$data = $conn1->Execute($sqlQuery);
//		$qcatName = $data->fields["name"];
		
		echo "<tr><td><a href='../question/editquestion.php?i=".$question->fields["id"]."'>".$question->fields["qstatement"]."</a>  - ".$qcatName."</td></tr>";
			$question->MoveNext(); 
		}

		echo "</table>";							
	}
	
		function displayQuestionGroups($qgroup)
	{
		echo "<table cellspacing=\"0\">";
		//This is where you display your query results
		while(!$qgroup->EOF)
		{
			echo "<tr><td><a href='../questiongroup/editquestiongroup.php?i=".$qgroup->fields["id"]."'>".$qgroup->fields["name"]."</a></td></tr>";
			$qgroup->MoveNext(); 
		}

		echo "</table>";							
	}

	
	function dropDownQuery($rowid,$rowname,$table,$selectedvalue)
	{
		$tmpstr = "";
		$sql = mysql_query("SELECT $rowid, $rowname FROM $table order by $rowname");
		while ($dropdown = mysql_fetch_array($sql))
			$tmpstr .= "<option value=\"".$dropdown[0]."\" ".($selectedvalue == $dropdown[0] ? "selected" : "").">".$dropdown[1]."</option>";
		return $tmpstr;
	}
	
	
	function dropDownOptions($rowid,$rowname,$selectedvalue,$options)
	{
		foreach ($options as $option){
		echo "<option value=\"".$option[$rowid]."\" ".($selectedvalue == $option[$rowid] ? "selected" : "").">".$option[$rowname]."</option>";
		}
	}
	
	
?>